package cn.tj.service.impl;

import cn.tj.entity.PageBean;
import cn.tj.entity.Type;
import cn.tj.mapper.TypeMapper;
import cn.tj.service.TypeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeServiceImpl implements TypeService {
    @Autowired
    private TypeMapper typeMapper;

    @Override
    public List<Type> list() {
        return typeMapper.list();
    }

    @Override
    public PageBean<Type> listByPage(Integer currentPage, Integer pageSize, Double minPrice, Double maxPrice) {
        PageBean<Type> pg = new PageBean<>();

        PageHelper.startPage(currentPage,pageSize);
        List<Type> tList=typeMapper.listByPage(minPrice,maxPrice);
        Page p=(Page) tList;

        pg.setTotal(p.getTotal());
        pg.setItems(p.getResult());
        return pg;
    }

    @Override
    public Type getById(Integer id) {
        return typeMapper.getById(id);
    }

    @Override
    public void edit(Type type) {
        typeMapper.edit(type);
    }

    @Override
    public void add(Type type) {
        typeMapper.add(type);
    }

    @Override
    public void deleteById(Integer id) {
        typeMapper.deleteById(id);
    }
}
